<!--
 * @Desc: 列表组件
 * @version: v1.00
 * @Author: harry
 * @Date: 2023-8-10 21:45:31
 * @LastEditors: harry
 * @LastEditTime: 2024-04-07 20:57:16
-->
<template>
  <div>
    <div
      class="card"
      v-for="item in list"
      :key="item.id"
      @click="toDetail(item)"
    >
      <div class="card_title">
        <span>
          {{ item.buildingLocationName }}{{ item.roomLocationName ? "/" : null
          }}{{ item.roomLocationName }}
        </span>
        <span
          class="card_title-staff"
          v-if="
            !item?.repairPerson && item?.persons?.length > 1 && !item?.status
          "
          @click.stop="openStaffPop(item?.persons, item.id)"
          >指定维修人员</span
        >
      </div>
      <div class="card_content">
        <svg-icon icon-class="tag" />
        <span>{{ item.repairTypeName }}</span>
      </div>
      <div class="card_content">
        <svg-icon icon-class="time" />
        <span>{{ item.status === 1 ? item.repairTime : item.createTime }}</span>
      </div>
      <div class="card_content">
        <svg-icon icon-class="remember" />
        <span>{{ item.personName }}</span>
        <div
          class="content_phone"
          v-if="item.personMobile"
          @click.stop="telPhone(item.personMobile)"
        >
          <span>{{ item.personMobile }}</span>
          <svg-icon icon-class="phone" />
        </div>
      </div>
      <div
        class="card_word"
        v-html="item.repairDesc.replace(/\n/g, '<br/>')"
      ></div>
    </div>
    <van-popup
      v-model:show="show"
      round
      position="bottom"
      :style="{ height: '50%' }"
      class="radioPop"
    >
      <van-radio-group v-model="checked">
        <van-cell-group inset>
          <van-cell
            v-for="item in persons"
            :key="item.personId"
            :title="item.personName"
            clickable
            @click="
              checked = item.personId;
              personName = item.personName;
            "
          >
            <template #right-icon>
              <van-radio :name="item.personId" />
            </template>
          </van-cell>
        </van-cell-group>
      </van-radio-group>
      <div class="btn">
        <Btn
          btnTitle="确定"
          @submit="secondConfirm"
          @cancel="
            show = false;
            checked = null;
          "
        />
      </div>
    </van-popup>
    <van-popup v-model:show="confirmShow" round class="confirmPop">
      <div>
        <div class="title">确定提交？</div>
        <div class="message">
          确定指定{{ personName }}进行维修，指定后将不能修改
        </div>
        <Btn
          btnTitle="确定"
          @submit="sureStaff"
          @cancel="confirmShow = false"
        />
      </div>
    </van-popup>
    <!-- <DialogPhone ref="phoneRef" /> -->
  </div>
</template>

<script setup lang="ts">
import Btn from "@/views/repairList/set/cnps/btn/index.vue";
import { sureRepairStaff } from "@/service/modules/repair/index";
import router from "@/router";
import { ref } from "vue";
import { Toast } from "vant";
defineProps({
  list: Array,
});
const emit = defineEmits(["refreshList"]);
const persons = ref([]);
const show = ref(false);
const confirmShow = ref(false);
const checked = ref(null);
const personName = ref(null);
const id = ref(null);
// const phoneRef = ref();
// 打电话
const telPhone = (phone) => {
  window.location.href = `tel:${phone}`;
};
const openStaffPop = (list, i) => {
  persons.value = list;
  show.value = true;
  id.value = i;
};
// 二次确认
const secondConfirm = () => {
  if (!checked.value) {
    Toast.fail("请指定维修人员");
    return false;
  }
  confirmShow.value = true;
};
const sureStaff = async () => {
  const res = await sureRepairStaff({
    personId: checked.value,
    id: id.value,
  });
  if (res.code === 0) {
    Toast.success("指定成功");
    show.value = false;
    confirmShow.value = false;
    emit("refreshList");
  } else {
    show.value = false;
    confirmShow.value = false;
    emit("refreshList");
    Toast.fail(res.msg);
    return false;
  }
};
// 跳详情
const toDetail = (item) => {
  if (!item?.repairPerson && item?.persons?.length > 1 && !item?.status) {
    Toast.fail("请指定维修人员");
    return false;
  }
  router.push("/repair/detail?id=" + item.id);
};
</script>

<style lang="less" scoped>
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 16px;
  border-radius: 10px;
  background-color: #ffffff;
  margin-bottom: 16px;
  .card_title {
    font-size: 16px;
    font-weight: 600;
    color: #303233;
    line-height: 24px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    &-staff {
      font-weight: 400;
      color: #3e77fa;
    }
  }
  .card_content {
    margin-bottom: 12px;
    font-size: 14px;
    color: #616366;
    line-height: 22px;
    position: relative;
    svg {
      margin-right: 11px;
    }
    .content_phone {
      position: absolute;
      top: 0;
      right: 0;
      span {
        font-size: 14px;
        font-family: PingFang SC, PingFang SC-Regular;
        font-weight: 400;
        text-align: RIGHT;
        color: #3e77fa;
        line-height: 22px;
      }
      svg {
        margin-left: 11px;
        color: #3e77fa;
      }
    }
  }
  .card_word {
    font-size: 14px;
    color: #616366;
    line-height: 22px;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
  }
}
/deep/ .radioPop {
  padding-top: 20px;
  .btn {
    position: absolute;
    bottom: 10px;
    width: 100%;
  }
}
/deep/ .confirmPop {
  width: 295px;
  border-radius: 10px;
  padding: 16px;
  .title {
    font-size: 16px;
    line-height: 22px;
    letter-spacing: 1px;
    font-weight: 500;
    text-align: center;
  }
  .message {
    margin-top: 20px;
    margin-bottom: 18px;
    padding: 0 8px;
    font-size: 14px;
    line-height: 22px;
    color: #919599;
    letter-spacing: 1px;
  }
  .btn {
    button {
      width: 124px;
      border-width: 0.5px;
    }
  }
}
</style>
